package com.hs.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Coursereply;
import com.hs.sfzy.mapper.CoursereplyMapper;
import com.hs.sfzy.mapper.UserMapper;
import com.hs.sfzy.service.CoursereplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @ClassName CoursereplyServiceImpl
 * @Description TODO
 * @Author zgy
 * @Date 2024年10月24日 17:22
 * @Version 1.0
 */
@Service
public class CoursereplyServiceImpl implements CoursereplyService {
    @Autowired
    private CoursereplyMapper coursereplyMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public int insert(Coursereply coursereply) {
        return coursereplyMapper.insert(coursereply);
    }

    @Override
    public int delete(int id) {
        return coursereplyMapper.delete(id);
    }

    @Override
    public int update(Coursereply coursereply) {
        return coursereplyMapper.update(coursereply);
    }

    @Override
    public List<Coursereply> selectAll(Coursereply coursereply) {
        return coursereplyMapper.selectAll(coursereply);
    }

    @Override
    public Coursereply selectById(int id) {
        return coursereplyMapper.selectById(id);
    }

    @Override
    public PageInfo<Coursereply> selectByPageInfo(int pageNum, int pageSize, Coursereply coursereply) {
        PageHelper.startPage(pageNum,pageSize);
        List<Coursereply> list = coursereplyMapper.selectAll(coursereply);
        PageInfo<Coursereply> pageInfo = new PageInfo<Coursereply>(list);
        return pageInfo;
    }

    @Override
    public List<Coursereply> selectByTalkId(Long talkId) {
        List<Coursereply> coursereplies = coursereplyMapper.selectByTalkId(talkId);
        for(Coursereply cr : coursereplies){
            cr.setUser(userMapper.getUserById(cr.getUserId()));
        }
        return coursereplies;
    }
}
